package main

import (
	"fmt"
	"log"
	"net/http"
	"os"
	"path/filepath"
	"strings"
)

func main() {
	// ex, err := os.Executable()
	// if err != nil {
	//     panic(err)
	// }
	// exPath := filepath.Dir(ex)
	// fmt.Println(GetCurrentDirectory())

	port := ":8089"
	filepathx := GetCurrentDirectory()
	fmt.Println("文件路径：", filepath.Join(filepathx, "web"))
	fmt.Println("浏览器打开: http://127.0.0.1" + port)
	http.Handle("/", http.FileServer(http.Dir(filepath.Join(filepathx, "web"))))
	http.ListenAndServe(port, nil)
}

func GetCurrentDirectory() string {
	//返回绝对路径  filepath.Dir(os.Args[0])去除最后一个元素的路径
	dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		log.Fatal(err)
	}

	//将\替换成/
	return strings.Replace(dir, "\\", "/", -1)
}
